#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=150, maxm=10, maxs=59049;

int pow3[maxm+1];

void initPow3() {
  pow3[0] = 1;
  for (int i=1; i<=maxm; i++) {
    pow3[i] = pow3[i-1]*3;
  }
}

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

int get(int n, int k) {
  return n/pow3[k-1]%3;
}

int set(int n, int k, int v) {
  return n-get(n, k)*pow3[k-1]+v*pow3[k-1];
}

void update(int v, int &ver, int &f) {
  if (v!=ver) {
    ver = v;
    f = -1;
  }
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  initPow3();

  static bool map[maxn+1][maxm+1];
  static int f[4][maxs], id[4][maxs+1], ver[4][maxs], book[4][maxs];
  int d, vers=0;
  scanf("%d", &d);
  for (int ti=1; ti<=d; ti++) {
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    memset(map, 0, sizeof map);
    for (int i=1; i<=k; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      map[x][y] = true;
    }

    ver[0][0] = vers;
    f[0][0] = 0;
    book[0][0] = vers;
    id[0][0] = 1;
    id[0][1] = 0;
    int p=0;
    for (int i=1; i<=n; i++) {
      for (int j=1; j<=m; j++) {
        p=(p+1)%4;
        vers++;
        id[p][0] = 0;
        int t;
        for (int k=1; k<=id[(p+3)%4][0]; k++) {
          int s=id[(p+3)%4][k];
          if (map[i][j]) {
            t=set(s, j, 0);
          } else {
            t=set(s, j, min(get(s, j)+1, 2));

          }
          update(vers-1, ver[(p+3)%4][s], f[(p+3)%4][s]);
          update(vers, ver[p][t], f[p][t]);
          f[p][t] = max(f[p][t], f[(p+3)%4][s]);
          if (f[p][t]>=0 && book[p][t]!=vers)  {
            book[p][t] = vers;
            id[p][++id[p][0]] = t;
          }
        }

        if (j>=2) {
          for (int k=1; k<=id[(p+2)%4][0]; k++) {
            int s=id[(p+2)%4][k];
            if (get(s, j)==2 && get(s, j-1)==2 && !map[i][j] && !map[i][j-1]) {
              t = set(set(s, j, 0), j-1, 0);
              update(vers-2, ver[(p+2)%4][s], f[(p+2)%4][s]);
              update(vers, ver[p][t], f[p][t]);
              if (f[(p+2)%4][s]>=0) {
                f[p][t] = max(f[p][t], f[(p+2)%4][s]+1);
                if (f[p][t]>=0 && book[p][t]!=vers)  {
                  book[p][t] = vers;
                  id[p][++id[p][0]] = t;
                }
              }
            }
          }
        }

        if (j>=3) {
          for (int k=1; k<=id[(p+1)%4][0]; k++) {
            int s=id[(p+1)%4][k];
            if (get(s, j)>=1 && get(s, j-1)>=1 && get(s, j-2)>=1 && !map[i][j] && !map[i][j-1] && !map[i][j-2]) {
              t = set(set(set(s, j, 0), j-1, 0), j-2, 0);
              update(vers-3, ver[(p+1)%4][s], f[(p+1)%4][s]);
              update(vers, ver[p][t], f[p][t]);
              if (f[(p+1)%4][s]>=0) {
                f[p][t] = max(f[p][t], f[(p+1)%4][s]+1);
                if (f[p][t]>=0 && book[p][t]!=vers)  {
                  book[p][t] = vers;
                  id[p][++id[p][0]] = t;
                }
              }
            }
          }
        }
      }
    }

    int ans=0;
    for (int k=1; k<=id[p][0]; k++) {
      int s=id[p][k];
      ans = max(ans, f[p][s]);
    }
    printf("%d\n", ans);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
